<template>
  <div class="components-container">
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" :height="height" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <outLibraryashMain ref="dialog" :orderType="order" @refreshData="getData"></outLibraryashMain>
    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
    <printmodal ref="printPdf"></printmodal>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btnCenter {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import outLibraryashMain from "./outLibraryashMain";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import staEndUse from "../basic/staEndUse";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";
import printmodal from "@/components/Pdf/Print";

const APPLY = "申请";
const MODIFY = "修改";
const DELETE = "删除";
const APPROVAL = "审批";
const GRANT = "发放";
const PRINTING = "打印";
const INFO = "详情";
const submits = "提交";
const nosubmits = "取消提交";

export default {
  name: "chargeProjectManage",
  mixins: [manage],
  data() {
    return {
      height:'700',
      title: null,
      loading: false,
      chargeProjectTypes: [],
      chaStatusTypes: [],
      chaReductionTypes: [],
      chaUintsTypes: [],

      selectData: {},
      chaData: {},

      //价格历史
      dataListLSJG: [],
      headListLSJG: [],
      //分页和排序
      pageOrderLSJG: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: 10,
        currentPage: 1
      },
      sweetModalWidth: 80,
      sweetModalMaxWidth: 840,
      hiddenColumn: false
    };
  },
  methods: {
    //收费项目查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        // Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Depot.QueryAshDpo,  
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取表头
    getheaderlist(){
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetOutLibraryColumns,
        res => {
          console.log(res);
          this.headList = res.data.content;
        }
      )
    },
    //收费项目历史价格查询
    getPriceHistory() {
      let data = {
        PageIndex: this.pageOrderLSJG.currentPage,
        PageSize: this.pageOrderLSJG.pageSize,
        OrderBy: this.pageOrderLSJG.orderType,
        OrderByType: this.pageOrderLSJG.orderSort,
        Data: { CpechaidEqual: this.currentRow.CHAID }
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().ChargeProject.QueryPriceHistory,
        res => {
          this.dataListLSJG = res.data.content.OutData;
          this.pageOrderLSJG.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //分页和排序
    pageChangeLSJG(value) {
      this.pageOrderLSJG = value;
      this.getPriceHistory();
    },
    //分页和排序
    pageChange(value) {
      this.pageOrder = value;
      this.getData();
    },
    //功能操作
    operate(order) {
        this.order = order;
        switch (this.order) {
            case APPLY:
                this.$refs.dialog.open(this.order);
                break;
            case MODIFY:
                this.$refs.dialog.open(this.order, this.currentRow.DPOID);
                break;
            case DELETE:
                this.deletes();
                break;
            case INFO:
                this.$refs.dialog.open(this.order, this.currentRow.DPOID);
                break;
            case submits:
                this.submission();
                break;
            case nosubmits:
                this.nosubmission();
                break;
            case APPROVAL:
                this.approvals();
                break;
            case GRANT:
                this.grants();
                break;
            case PRINTING:
                this.$refs.printPdf.open(
                    "打印出库明细",
                    this.currentRow.DPOID
                );
                break;
            default:
        }
    },
    //删除
    deletes() {
        this.$confirm("确认是否删除该数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        })
            .then(callback => {
                let data = {
                    DPOID: this.currentRow.DPOID
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Depot.DeleteAshDpo,
                    res => {
                        this.getData();
                    }
                );
            })
            .catch(() => {
                this.$message({
                    type: "info",
                    message: "已取消"
                });
            });
    },
    //出库提交
        submission() {
            this.$confirm("确认是否提交该数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.SubmitAshDpo,
                        res => {
                            this.$message({
                                type: "success",
                                message: "提交成功!"
                            });
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        //取消提交
        nosubmission(){
            this.$confirm("确认是否取消提交该数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.CancelGrantAshDpo,
                        res => {
                            this.$message({
                                type: "success",
                                message: "取消成功成功!"
                            });
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
    //删除
    DpgDelete(id){
        this.$confirm("确认是否删除该数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
              let data = {
                DPGID: id
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().Depot.DeleteAshDpo,
                res => {
                  this.getData();
                }
              );
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
    btnShow(btn) {
        let status = "";
        if (this.currentRow) {
            status = this.currentRow.DPOSTATUS;
        }
        if (btn === APPLY) return true;
        if (!this.currentRow) return false;
        if (btn === PRINTING) return !(status === "A");
        if (
            btn === submits ||
            btn === MODIFY ||
            btn === DELETE
        )
            return status === "A";
        if (btn === APPROVAL) return status === "B";
        if (btn === GRANT) return status === "C";
        if (btn === nosubmits) return status === "D";
    },
    //数据重置
    dataRepeat() {
      this.chaData = {};
    },
  },
  components: {
    sweetModal,
    dataTable,
    outLibraryashMain,
    staEndUse,
    printmodal
  },
  mounted() {},
  created() {
    this.getData();
    this.getheaderlist();
  }
};
</script>
